package com.example.exampleproject.enumutils;

import java.util.HashMap;
import java.util.Map;

public enum GenderEnum3 {
    MALE(1, "男"),
    FEMALE(2, "女"),
    UNKNOWN(3, "未知");
    private Integer code;
    private String sex;

    private static Map<Integer, GenderEnum3> sexEnumMap = new HashMap<>();

    static {
        for (GenderEnum3 GenderEnum : GenderEnum3.values()) {
            sexEnumMap.put(GenderEnum.getCode(), GenderEnum);
        }
    }
    //根据code获取枚举
    public static GenderEnum3 getGenderEnumByCode(int code) {
        return sexEnumMap.get(code);
    }


    private GenderEnum3(Integer code, String sex){
        this.code=code;
        this.sex=sex;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "GenderEnum{" +
                "code='" + code + '\'' +
                ", sex='" + sex + '\'' +
                '}';
    }
}
